import com.cw.japp.Role
import com.cw.japp.User
import com.cw.japp.UserRole

class BootStrap {

    def init = { servletContext ->
		def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
		def userRole = new Role(authority: 'ROLE_USER').save(flush: true)
		def studioRole = new Role(authority: 'ROLE_STUDIO').save(flush: true)
		def modelRole = new Role(authority: 'ROLE_MODEL').save(flush: true)
		//def users = new Users(login : "admin", password : "admin", email: "admin@cgirls.com", description : "", firstName:"Admin", lastName : "", userType : "ROLE_ADMIN")
		def testUser = new User(username: 'admin', enabled: true, password: 'admin', email: "admin@cgirls.com", description : "", firstName:"Admin", lastName : "")
		testUser.save(flush: true)
		//users.save(flush: true);
	
		UserRole.create testUser, adminRole, true
		UserRole.create testUser, userRole, true
		UserRole.create testUser, studioRole, true
		UserRole.create testUser, modelRole, true
		
		
	
		assert Role.count() == 4
		
		Date.metaClass.getAge = { new Date().year - delegate.year }
    }
    def destroy = {
    }
}
